<?php

require_once("conn.php");
$result = true;
$db = new DBC();
if (isset($_GET['ids'])) {
    $ids = $_GET['ids'];
    $ids = trim($ids);
    $array = explode(",", $ids);
    foreach ($array as $packid) {
        if ($packid != '') {
            $sql = "SELECT * FROM t_pack WHERE packid = " . $packid;
            $data = $db->fetchData($sql);
            if ($data != null && count($data) > 0) {
                if (file_exists($data[0]['soundURL'])) {
                    unlink($data[0]['soundURL']);
                }
                if (file_exists($data[0]['imageURL'])) {
                    unlink($data[0]['imageURL']);
                }
                if (file_exists($data[0]['ImageAid1URL'])) {
                    unlink($data[0]['ImageAid1URL']);
                }
                if (file_exists($data[0]['ImageAid2URL'])) {
                    unlink($data[0]['ImageAid2URL']);
                }
            }
            $sql = "UPDATE t_product SET packid = -1 WHERE packid = " . $packid;
            $db->execute($sql);
            $sql = "DELETE FROM t_pack WHERE packid = " . $packid;
            if ($db->execute($sql)) {
                //success
                //            echo "<script language='javascript'>alert('\u6210\u529f'); </ script>";
            } else {
                //failue
                $result = false;
            }
        }
    }
}
if (!$result) {
    echo "<script language='javascript'>alert('\u5931\u8d25'); </script>";
}
if (isset($_GET['page'])) {
    $page = $_GET['page'];
} else {
    $page = 0;
}
echo "<script language='javascript'>location='packList.php?menu=pack&page=" . $page . "';</script>";
?>
